library(SDMTools)
wd='/home/jc148322/rob/';setwd(wd)

#read in the asciis & create base.asc
bdall=read.asc('Bdall.asc')
bdwet=read.asc('Bdwet.asc')


#read in the data
pos=read.csv('coord.csv',as.is=TRUE)
threshold=read.csv('maxentResults.csv')
threshold=threshold$Minimum.training.presence.logistic.threshold

#read in the threshold to create sigdiff
threshold=read.csv('maxentResults.csv')
threshold=threshold$Minimum.training.presence.logistic.threshold
bdall[which(bdall<threshold[1])]=0; #set values below threshold to 0
bdwet[which(bdwet<threshold[2])]=0; #set values below threshold to 0

pos$bdall[which(pos$bdall<threshold[1])]=0; #set values below threshold to 0
pos$bdwet[which(pos$bdwet<threshold[2])]=0;

twet=pos[,c('bc01','bc12','bdwet')]
twet=twet[which(twet$bdwet>0),]
twet$bdwet=round(twet$bdwet*100)

tall=pos[,c('bc01','bc12','bdall')]
tall=tall[which(tall$bdall>0),]
tall$bdall=round(tall$bdall*100)

palette(colorRampPalette(c("tan","forestgreen"))(100))
png('gradient_test.png', width=16,height=8,units='cm', res=300,pointsize=5)
	par(mfrow=c(1,2), mar=c(5,5,1,1))
        plot(tdata[,1],tdata[,2], xlab='Annual mean temperature',ylab='Annual rainfall',xlim=range(tdata[,1],na.rm=T),ylim=range(tdata[,2],na.rm=T), type='n',cex.lab=1, cex.axis=1, font.lab='2')

        points(pos$bc01[which(pos$bdwet>0)],pos$bc12[which(pos$bdwet>0)],col=twet$bdwet,pch=15)
		text(22,6000, 'bdwet')
		
		plot(tdata[,1],tdata[,2], xlab='Annual mean temperature',ylab='Annual rainfall',xlim=range(tdata[,1],na.rm=T),ylim=range(tdata[,2],na.rm=T), type='n',cex.lab=1, cex.axis=1, font.lab='2')

        points(pos$bc01[which(pos$bdall>0)],pos$bc12[which(pos$bdall>0)],col=tall$bdall,pch=15)
		text(22,6000,'bdall')
dev.off()
